import pathlib
import datetime
import uuid
import pymysql

# 获取项目根目录的str格式
BASE_DIR_STR = pathlib.Path(__file__).parent.parent.as_posix()

# 获取项目根目录的Pathlib格式，后续直接使用'/'拼接其他目录即可
BASE_DIR = pathlib.Path(BASE_DIR_STR)

# 测试用例路径
CASE_PATH = BASE_DIR / "data"

# allure相关路径
ALLURE_RESULTS = BASE_DIR / "results"

ALLURE_REPORTS = BASE_DIR / "reports"

# extract提取响应值文件路径
EXTRACT_RES_FILE_PATH = BASE_DIR / "extract.yml"

# 日志相关处理
LOG_NAME = "NB接口测试框架"
LOG_FILE_PATH = BASE_DIR / "logs" / (datetime.datetime.now().strftime('%Y-%m-%d'))
LOG_FILE_NAME = LOG_FILE_PATH / (datetime.datetime.now().strftime('%Y-%m-%d-%H') + '.log')
LOG_CHARSET = "utf-8"
LOG_BACKUP_COUNT = 31
LOG_WHEN = 'd'

# 接口api配置文件路径
API_CONFIG_PATH = BASE_DIR / "config.yaml"

# flask mock api配置信息
# 监听端口
API_PORT = 8000
# 监听地址
API_HOST = "127.0.0.1"

# MYSQL配置
"""
    creator: 使用链接数据库的模块
    maxconnections: 连接池允许的最大连接数，0和None表示不限制连接数
    mincached: 初始化时，链接池中至少创建的空闲的链接，0表示不创建
    maxcached: 链接池中最多闲置的链接，0和None不限制
    blocking: 连接池中如果没有可用连接后，是否阻塞等待。True，等待；False，不等待然后报错
    setsession: 开始会话前执行的命令列表。如：["set datestyle to ...", "set time zone ..."]
    ping: MySQL服务端，检查是否服务可用。
          如：0 = None = never, 1 = default = whenever it is requested, 2 = when a cursor is created, 
          4 = when a query is executed, 7 = always
"""
MYSQL_CONFIG = {
    "creator": pymysql,
    "maxconnections": 5,
    "mincached": 2,
    "maxcached": 3,
    "blocking": True,
    "setsession": [],
    "ping": 0,
    "host": '127.0.0.1',
    "port": 3306,
    "user": 'dig_user',
    "password": 'dig123',
    "database": 'dig',
    "charset": 'utf8'
}

# flask配置
FLASK_CONFIG = {
    "DEBUG": True,
    "JSON_AS_ASCII": False,
    "SQLALCHEMY_DATABASE_URI": "mysql+pymysql://root:root123@127.0.0.1:3306/test?charset=utf8mb4",
    "SECRET_KEY": str(uuid.uuid4()).encode()
}

# 待上传文件的路径
UPLOADING_FILE_PATH = BASE_DIR / "upload_files"

# 测试环境需要清空的表
TABLES = ["api_collect", "api_userinfo", "api_comment", "api_news", "api_recommend", "api_topic"]